package com.stu.mall.search.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class GmallElasticSearchConfig {

    private static String HOSTNAME = "192.168.205.10";
    private static Integer PORT = 9200;
    private static String SCHEME = "http";

    public static final RequestOptions COMMON_OPTIONS;


    static {
        RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
        // builder.addHeader("Authorization", "Bearer " + TOKEN);
        // builder.setHttpAsyncResponseConsumerFactory(
        //         new HttpAsyncResponseConsumerFactory
        //                 .HeapBufferedResponseConsumerFactory(30 * 1024 * 1024 * 1024));
        COMMON_OPTIONS = builder.build();
    }


//    /**
//     * 集群配置方式
//     * @return
//     */
//     @Bean
//     public RestHighLevelClient esRestClient(){
//         RestHighLevelClient client = new RestHighLevelClient(
//                 RestClient.builder(
//                         new HttpHost("192.168.137.14", 9200, "http"),
//                         new HttpHost("192.168.137.15", 9200, "http"),
//                         new HttpHost("192.168.137.16", 9200, "http")
//                 )
//         );
//         return  client;
//     }


    @Bean
    public RestHighLevelClient esRestClient() {
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(new HttpHost(HOSTNAME, PORT, SCHEME)));
        return client;
    }
}
